//
//  LJMMain_ViewController.m
//  wind
//
//  Created by 李金明 on 16/1/9.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJMMain_ViewController.h"
#import "LJMUserCollectionViewCell.h"
#import "LJMRecommendCollectionViewCell.h"
#import "LJMDiscoverCollectionViewCell.h"
#import "LJMLunbo_Model.h"
#import "LJMRink_Model.h"
#import "LJMListen_Model.h"
#import "LJMRank_sonerViewController.h"
#import "LJMRank_sonerModel.h"
#import "SYP_BaseToolbar.h"
#import "LJM_SouSuo_ViewController.h"
#import "Masonry.h"
#import "LJM_ActivityMoreVC_Model.h"
#import "LJM_ActivityMoreVC_ViewController.h"
#import "LJM_FM_ViewController.h"
#import "LJMBase_FM_Model.h"
#import "UIImageView+WebCache.h"
#import "LJM_SONG_ViewController.h"
#import "LJMBase_FM_ONEModel.h"
#import "LJM_SONG_Main_Model.h"
#import "SYP_playerMusicTableViewCell.h"  // 播放列表的自定义cell_SYP
#import <STKAudioPlayer.h>
#import "LJM_RANK_ViewController.h"
#import "LJM_ListenMove_ViewController.h"
#import "LJM_HotSong_Model.h"
#import "LJM_SONG_Root_Sub_ViewController.h"
#import "LJMNetworkTool.h"
//barbutton 左面的坐标
#define LEFTBARBUTTONHEIGHT 44
#define LEFTBARBUTTONWIDTH 50

#pragma 更换壁纸界面
#import "SYP_WallpaperViewController.h"
#import "SYP_LeftViewController.h"
#import "LJM_RANK_WebView_ViewController.h"

// 音乐播放界面_SYP
#import "SYPMusicPlay_ViewController.h"
#define MUSICIMAGELEFT 10  // 歌手头像距左侧的距离
#define MUSICIMAGESIZE 40  // 歌手头像大小
#define LABLETOP 10  // 歌名距顶部距离
#define LABLEIN 5 // 歌名歌手名之间的距离
#define LABLELEFT 15 // 歌名左侧距离
#define PLAYRIGHT 40 // 播放右侧的距离
#define PLAYSIZE 25 // 播放按钮的大小
#define LISTRIGHT 20 // 列表右侧的距离
#define TITLELEFT 20  // "正在播放"右侧距离
#define TITLEWIDTH 100 // "正在播放"宽度
#define TITLEHEIGHT 30 // "正在播放"高度


//数据接口
//发现的接口
#define DISCOVERDATA @"http://api.dongting.com/frontpage/frontpage?v=v8.1.0.2015071519&f=f168&s=s200&version=0"
//发现中listenmover的接口
#define LISTENMOVEURL @"http://api.favorite.ttpod.com/favorite/song/plaza?random=0&version=0&app=ttpod&v=v8.1.3.2015112716&user_id=0&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=7.0.4&active=1&net=2&openudid=1389d9dc18cb741587d90a5aead8646421f95dc0&idfa=C9BC818C-A0F5-4F04-8F8D-841910E08DF7&utdid=VmGiKEXHDQ0DAIL2FOnFFzxV&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude="



@interface LJMMain_ViewController () <UICollectionViewDataSource, UICollectionViewDelegate, DiscoverChangeVCDelegate, UITableViewDataSource, UITableViewDelegate, ljmSuggestPageDelegate, BaseRankBackDelegate, BaseFMBackDelegate, BaseSONGBackDelegate, BaseRANKBackDelegate, ListenMOVEBackNavigationDelegate, SubBackNavigationDelegate, RANK_WebView_BackDelegate, BaseActionMoreVCBackDelegate, BasesousuoBackDelegate>
#pragma 搜索的返回动作
- (void)backSousuoVCAction;
#pragma actionMore的返回动作
- (void)backActionMoreVCAction;
#pragma webView返回协议动作的方法
- (void)backRANK_WebView_Delegate;
#pragma activity到webView的方法
- (void)changeActivityToWebView:(NSString *)str;
#pragma activity更多切换到VC中 更多
- (void)changeActivityMoveToVC:(NSString *)str;
#pragma song_root_subVC的协议方法
- (void)SubBackNavigationDelegate;
#pragma hotSong进入song_root_sub界面
- (void)changeHotSongToSong_Root_sub:(LJM_HotSong_Model *)model;
#pragma ListenMove中的返回动作
- (void)ListenMOVEBackNavigationDelegate;
#pragma ListentableViewCell的协议方法 cell点击
- (void)changeCellVCUrl:(NSInteger)n;
#pragma RANK中返回的动作
- (void)backRANKAction;

#pragma FM中返回的动作
- (void)backFMAction;
#pragma rank中的返回动作
- (void)backRankAction;
#pragma SONG中的返回动作
- (void)backSONGAction;
#pragma DiscoverVC的协议方法进行页面跳转
- (void)changeVCUrl:(NSString *)str type:(NSString *)type;
#pragma DiscoverVC的协议方法 - ListentableViewCell的协议方法 MOVE
- (void)changeMoveVCUrl:(NSString *)str;


@property (nonatomic, retain) UIImageView *headImageV;
@property (nonatomic, retain) UICollectionView *mainCV;
@property (nonatomic, retain) UIButton *rightBut;
@property (nonatomic, retain) UIView *rightBarView;
@property (nonatomic, retain) UIButton *userBut;//我的
@property (nonatomic, retain) UIButton *recommendBut;//推荐
@property (nonatomic, retain) UIButton *discoverBut;//发现

@property (nonatomic, retain) LJMUserCollectionViewCell *userCVC;
@property (nonatomic, retain) LJMRecommendCollectionViewCell *recommendCVC;
@property (nonatomic, retain) LJMDiscoverCollectionViewCell *discoverCVC;
@property (nonatomic, retain) UIView *leftBarView;

//发现数据
@property (nonatomic, retain) NSMutableArray *discoverDataArr;

//推荐数据
@property (nonatomic, retain) NSMutableArray *suggestDataArr;

#pragma 播放控制条_SYP
@property (nonatomic, retain) SYP_BaseToolbar *playerToolbar;
@property (nonatomic, retain) UIView *playerView;
@property (nonatomic, retain) UIImageView *singerImageV;
@property (nonatomic, retain) UILabel *singerName;
@property (nonatomic, retain) UILabel *musicName;
@property (nonatomic, retain) UIButton *playButton;
@property (nonatomic, retain) UIButton *musicListButton;


#pragma 正在播放列表_SYP
@property (nonatomic, retain) NSMutableArray *playerMusicArr; // 正在播放的音乐数组
@property (nonatomic, copy) NSString *playerMusicUrl;
@property (nonatomic, assign) NSInteger mainIndex;  // 当前正在播放哪首歌
@property (nonatomic, retain) UITableView *musicListTableView;
@property (nonatomic, retain) UILabel *playnum;  //
@property (nonatomic, retain) UIView *nightViews;  // 弹出列表时铺的一层透明背景
@property (nonatomic, retain) UIView *views;
@property (nonatomic, retain) UITapGestureRecognizer *tapBackgrandGR;
@property (nonatomic, retain) SYPMusicPlay_ViewController *musicVC;
@property (nonatomic, assign) NSInteger tempIndex;

#pragma 更换壁纸界面
@property (nonatomic, retain) SYP_WallpaperViewController *wallpaperVC;
@end

@implementation LJMMain_ViewController
- (void)dealloc
{
    [_rightBarView release];
    [_rightBut release];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeState" object:nil];
    [_playerMusicUrl release];
    [_leftBarView release];
    [_playerMusicArr release];
    [_wallpaperVC release];
    [_musicVC release];
    [_tapBackgrandGR release];
    [_views release];
    [_nightViews release];
    [_playnum release];
    [_musicListTableView release];
    [_singerImageV release];
    [_musicName release];
    [_playButton release];
    [_musicListButton release];
    [_playerView release];
    [_playerToolbar release];
    Block_release(myBlock);
    [_discoverDataArr release];
    [_headImageV release];
    [_userCVC release];
    [_recommendCVC release];
    [_discoverCVC release];
    [_mainCV release];
    [_userBut release];
    [_recommendBut release];
    [_discoverBut release];
    [_leftBarButton release];
    [super dealloc];
}

#pragma 播放条状态的调整_SYP
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([SYPMusicPlay_ViewController shareMusicPlayVC].states == 1) {
        NSLog(@"播放状态");
        self.playButton.selected = YES;
    } else {
        NSLog(@"暂停状态");
        self.playButton.selected = NO;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeState) name:@"changeState" object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeIndex:) name:@"changeIndex" object:nil];
    
    // 接受通知传过来正在播放的行数
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexAction:) name:@"playIndex" object:nil];
    
//添加navigationbar
    [self addNavigationBar];
    
//添加toolbar_SYP
    [self addToolBar];
    
//添加头视图上的三个button
    [self addHeadBut];
//添加个移动的View在navigation上(小白条)
    [self creatHeatView];
//添加主controllView在View上
    [self creatMainControllView];
//获取发现的数据
    [self getDiscoverData];
//获取推荐的数据
    [self getSuggestData];
    
    self.nightViews = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - 60)];
    self.nightViews.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.308];
    [self.navigationController.view addSubview:self.nightViews];
    [self.nightViews release];

    
#pragma 实现创建音乐歌单的列表_SYP
    [self creatMusicListTableView];
    
}

- (void)indexAction:(NSNotification *)sender
{
    NSDictionary *dic = sender.userInfo;
    NSString *n = dic[@"myIndex"];
    NSLog(@"接受通知: 当前行数: %@", n);
    self.mainIndex = [n intValue];
    LJMListen_Model *mod = self.playerMusicArr[self.mainIndex];
    self.musicName.text = mod.name;
    self.singerName.text = mod.singerName;
    [self.singerImageV sd_setImageWithURL:[NSURL URLWithString:mod.picUrl] placeholderImage:[UIImage imageNamed:@"CD"]];
}

- (void)changeState
{
    self.musicVC = [SYPMusicPlay_ViewController shareMusicPlayVC];
    NSLog(@"接到通知");
    NSMutableArray *myMusicArr = self.musicVC.MusicsArr;
    NSInteger myindex = self.musicVC.index;
    NSInteger mystate = self.musicVC.states;
    self.playerMusicArr = myMusicArr;
    self.mainIndex = myindex;
    
    if (0 != myMusicArr.count) {
        
        LJMListen_Model *mod = myMusicArr[myindex];
        self.musicName.text= mod.name;
        self.singerName.text = mod.singerName;
        [self.singerImageV sd_setImageWithURL:[NSURL URLWithString:mod.picUrl] placeholderImage:[UIImage imageNamed:@"CD"]];
        
    }
    
    [self.musicListTableView reloadData];
    
    // 是播放状态
    if (1 == mystate) {
        self.playButton.selected = 1;
    } else {
        self.playButton.selected = 0;
    }
}

#pragma 显示toolBar_SYP
- (void)addToolBar
{
    [self.navigationController setToolbarHidden:NO animated:YES];
    
    self.navigationController.toolbar.bounds = CGRectMake(0, SCREEN_HEIGHT - 160, SCREEN_WIDTH, 160);
    [self.navigationController.toolbar addSubview:[self creatPlayerView]];

}

#pragma 自定义toolBar样式_SYP
- (UIView *)creatPlayerView
{
    self.playerView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 180, SCREEN_WIDTH, 180)];
    self.playerView.backgroundColor = [UIColor colorWithRed:0.930 green:0.927 blue:0.970 alpha:1.000];
    
    // 该View用来确定位置
    self.views = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
    self.views.backgroundColor = self.playerView.backgroundColor;
    [self.playerView addSubview:self.views];

    
    // 歌手头像
    self.singerImageV = [UIImageView new];
    [self.views addSubview:self.singerImageV];
    
    [self.singerImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.views);
        make.left.mas_equalTo(MUSICIMAGELEFT);
        make.width.height.mas_equalTo(MUSICIMAGESIZE);
        
    }];
    self.singerImageV.image = [UIImage imageNamed:@"CD"];
    self.singerImageV.layer.masksToBounds = YES;
    self.singerImageV.layer.cornerRadius = MUSICIMAGESIZE / 2;
    [_singerImageV release];
    
    // 歌名
    self.musicName = [UILabel new];
    self.musicName.text = @"暂无歌曲";
    self.musicName.font = [UIFont systemFontOfSize:14 * SCREEN_ONE];
    [self.views addSubview:self.musicName];
    
    // 歌手名
    self.singerName = [UILabel new];
    self.singerName.text = @"暂无";
    self.singerName.font = [UIFont systemFontOfSize:13 * SCREEN_ONE];
    self.singerName.textColor = [UIColor lightGrayColor];
    [self.views addSubview:self.singerName];
    
    
    
    [self.musicName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.views).with.offset(LABLETOP);
        make.bottom.equalTo(self.singerName.mas_top).with.offset(-LABLEIN);
        make.height.equalTo(self.singerName.mas_height);
        make.left.equalTo(self.singerImageV.mas_right).with.offset(LABLELEFT);
        make.width.mas_equalTo(SCREEN_WIDTH / 2.5);
        
        
    }];
    
    [self.singerName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.views).with.offset(-LABLETOP);
        make.top.equalTo(self.musicName.mas_bottom).with.offset(LABLEIN);
        make.height.equalTo(self.musicName.mas_height);
        make.left.equalTo(self.singerImageV.mas_right).with.offset(LABLELEFT);
        make.width.mas_equalTo(SCREEN_WIDTH / 2.5);
    }];
    
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playButton setImage:[UIImage imageNamed:@"播放"] forState:UIControlStateNormal];
    [self.playButton setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateSelected];
    [self.playButton addTarget:self action:@selector(playButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.views addSubview:self.playButton];
    
    
    self.musicListButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.musicListButton setImage:[UIImage imageNamed:@"播放列表"] forState:UIControlStateNormal];
    [self.musicListButton addTarget:self action:@selector(musicListButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.views addSubview:self.musicListButton];
    
    // 播放按钮的约束
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.musicListButton.mas_left).with.offset(-PLAYRIGHT);
        make.centerY.equalTo(self.views);
        make.height.mas_equalTo(PLAYSIZE);
        make.width.mas_equalTo(PLAYSIZE);
        
    }];
    
    // 播放列表按钮的约束
    [self.musicListButton mas_makeConstraints:^(MASConstraintMaker *make) {
    
        make.right.equalTo(self.views).with.offset(-LISTRIGHT);
        make.centerY.equalTo(self.views);
        make.height.mas_equalTo(PLAYSIZE);
        make.width.mas_equalTo(PLAYSIZE);
        
    }];
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction)];
    [self.views addGestureRecognizer:tapGR];
    [tapGR release];
    
    
    return self.playerView;
}


#pragma 播放暂停的控制按钮_SYP
- (void)playButtonAction:(UIButton *)sender
{
    // 点击暂停
    if (sender.selected) {
        NSLog(@"暂停了");
        sender.selected = NO;
        self.musicVC.states = 0;
        [[SYPMusicPlay_ViewController shareMusicPlayVC].player pause];
        
    // 点击播放
    } else {
        
        if (0 == self.musicVC.musicURL.length) {
            
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请选择要播放的歌曲" preferredStyle:UIAlertControllerStyleAlert];
            [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                
            }]];
            [self presentViewController:alertC animated:YES completion:^{
                
                
            }];
            
            // 点击播放
        } else {
            
            sender.selected = YES;
            self.musicVC.states = 1;
            [[SYPMusicPlay_ViewController shareMusicPlayVC].player resume];
            [SYPMusicPlay_ViewController shareMusicPlayVC].playButton.selected = YES;
            NSLog(@"开始播放了");
        }
    }
   
}

#pragma 正在播放的音乐列表_SYP
- (void)musicListButtonAction:(UIButton *)sender
{
    
    if (sender.selected) {
        
        sender.selected = NO;
        self.nightViews.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 60);
        
        [UIView animateWithDuration:0.5 animations:^{

        self.musicListTableView.frame = CGRectMake(0, (SCREEN_HEIGHT - 60) / 2, SCREEN_WIDTH, (SCREEN_HEIGHT - 60) / 2 );
        }];
        
    } else {
        
        sender.selected = YES;
        self.nightViews.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - 60);
        [UIView animateWithDuration:0.5 animations:^{
            
        self.musicListTableView.frame = CGRectMake(0, SCREEN_HEIGHT - 65, SCREEN_WIDTH, 0);
            
        }];
    }
}

#pragma 点击跳转播放界面tap_SYP
- (void)tapGRAction
{

    self.musicVC = [SYPMusicPlay_ViewController shareMusicPlayVC];
    
    [self.navigationController presentViewController:self.musicVC animated:YES completion:^{
        
        
    }];
    
    self.musicListButton.selected = YES;
    self.nightViews.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - 60);
    [UIView animateWithDuration:0.5 animations:^{
        
        self.musicListTableView.frame = CGRectMake(0, SCREEN_HEIGHT - 65, SCREEN_WIDTH, 0);
        
    }];
}

#pragma 正在播放音乐列表的创建_SYP
- (void)creatMusicListTableView
{
    self.musicListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 65, SCREEN_WIDTH, 0) style:UITableViewStylePlain];
    self.musicListTableView.delegate = self;
    self.musicListTableView.dataSource =self;
    self.musicListTableView.bounces = NO;
    self.musicListTableView.showsVerticalScrollIndicator = NO;
    [self.nightViews addSubview:self.musicListTableView];
    [_musicListTableView release];
}

// 区头的"正在播放"
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    view.backgroundColor = [UIColor colorWithRed:0.411 green:0.638 blue:1.000 alpha:1.000];
    
    
    // 正在播放
    UILabel *playLabel = [UILabel new];
    playLabel.text = @"正在播放";
    [view addSubview:playLabel];
    [playLabel release];
    
    // 列表里歌曲个数
    self.playnum = [UILabel new];
    self.playnum.text = @"/23首";
    self.playnum.textColor = [UIColor lightGrayColor];
    [view addSubview:self.playnum];
    [_playnum release];
    
    // 添加约束
    [playLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(view);
        make.left.equalTo(view).with.offset(TITLELEFT);
        make.width.mas_equalTo(TITLEWIDTH);
        make.height.mas_equalTo(TITLEHEIGHT);
        
    }];
    
    return view;
}


// 区头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}


// cell的个数_SYP
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.playerMusicArr.count;

}

// 创建歌单cell_SYP
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellStr = @"cell";
    SYP_playerMusicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (nil == cell) {
        cell = [[SYP_playerMusicTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    cell.backgroundColor = [UIColor colorWithWhite:0.915 alpha:1.000];
    cell.musicNum.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    
    if (0 != self.playerMusicArr.count) {
        LJMListen_Model *mod = self.playerMusicArr[indexPath.row];
        cell.musicName.text = mod.name;
        cell.singerName.text = mod.singerName;
    }
    return cell;
}


#pragma 点击歌单进行切歌
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSLog(@"点击的第%ld行", indexPath.row);
    self.mainIndex = indexPath.row;
    self.musicVC.index = indexPath.row;
    LJMListen_Model *mod = nil;
    
    if (0 != self.playerMusicArr.count) {
        mod = self.playerMusicArr[self.mainIndex];
        self.singerName.text = mod.singerName;
        self.musicName.text = mod.name;
        NSMutableDictionary *dic = mod.auditionListArr[1];
        self.musicVC.musicURL = dic[@"url"];
    }
    if (self.musicVC.player) {
        NSLog(@"已经有播放器");
        if (self.musicVC.musicURL == self.playerMusicUrl) {
            NSLog(@"点击的同一首歌");
            switch (self.musicVC.player.state) {
                    
                case STKAudioPlayerStatePlaying:
                    NSLog(@"播放状态, 暂停");
                    [self.musicVC.player pause];
                    self.playButton.selected = NO;
                    self.musicVC.states = 0;
                    break;
                    
                case STKAudioPlayerStatePaused:
                    NSLog(@"暂停状态, 播放");
                    [self.musicVC.player resume];
                    self.playButton.selected = YES;
                    self.musicVC.states = 1;
                    break;
                    
                case STKAudioPlayerStateBuffering:
                    NSLog(@"缓冲状态");
                    break;
                    
                default:
                    break;
            }
        } else {
            NSLog(@"点击的不是同一首歌");
            [self.musicVC.player stop];
            [self.musicVC.player release];
            [self.musicVC creatPlayerWithMusicName:self.musicVC.musicURL];
            self.playerMusicUrl = self.musicVC.musicURL;
            self.musicVC.states = 1;
            self.playButton.selected = YES;
        }
        
    } else {
        NSLog(@"还没有播发器");
    }
}

#pragma 获取发现数据
- (void)getDiscoverData
{

[LJMNetworkTool getNetWithURL:DISCOVERDATA body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {

    NSArray *allArr = [responseObject objectForKey:@"data"];
    self.discoverDataArr = [NSMutableArray arrayWithArray:allArr];


    
#pragma 缓存数据到本地
    NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[DISCOVERDATA hash]];
    // 存储的沙盒路径
    NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    // 归档
    [NSKeyedArchiver archiveRootObject:responseObject toFile:[path_doc stringByAppendingPathComponent:path]];
    
    [self.mainCV reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
    
    // 缓存的文件夹
    NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[DISCOVERDATA hash]];
    NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    // 反归档
    id result = [NSKeyedUnarchiver unarchiveObjectWithFile:[path_doc stringByAppendingPathComponent:path]];
    
    if (result) {
        
        NSArray *allArr = [result objectForKey:@"data"];
        self.discoverDataArr = [NSMutableArray arrayWithArray:allArr];

            [self.mainCV reloadData];
    } else {
        NSLog(@"error = %@", error);
    }
}];
    
}

#pragma 获取推荐数据
- (void)getSuggestData
{
    [LJMNetworkTool getNetWithURL:@"http://api.dongting.com/frontpage/module/songlist?moduleId=2794&utdid=UOG2rGI3l64DAFB0qPHuqs0m" body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        self.suggestDataArr = [NSMutableArray array];
        NSMutableArray *tempArr = [responseObject objectForKey:@"data"];
        for (NSMutableDictionary *dic in tempArr) {
            LJMListen_Model *model = [[LJMListen_Model alloc] init];
            model.name = [dic objectForKey:@"name"];
            model.singerName = [dic objectForKey:@"singerName"];
            model.picUrl = [dic objectForKey:@"picUrl"];
            model.auditionListArr = [dic objectForKey:@"auditionList"];
            [self.suggestDataArr addObject:model];
            [model release];
        }
        
        
        [self.mainCV reloadData];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"error = %@", error);
    }];
}

#pragma /添加个移动的View在navigation上(小白条)
- (void)creatHeatView
{
    self.headImageV = [[UIImageView alloc] init];
    self.headImageV.frame = CGRectMake(0, 0, self.userBut.frame.size.width - 10, 3);
    self.headImageV.center = CGPointMake(self.userBut.center.x, self.userBut.frame.size.height + self.userBut.frame.origin.y - 1.5);
    self.headImageV.image = [UIImage imageNamed:@"head"];
    [self.navigationController.navigationBar addSubview:self.headImageV];
    [_headImageV release];
    
}

#pragma 添加主controllView在View上
- (void)creatMainControllView
{
    UICollectionViewFlowLayout *flowLy = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    flowLy.itemSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height - self.navigationController.navigationBar.frame.size.height);
    
    flowLy.minimumLineSpacing = 0;
    
    flowLy.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.mainCV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height) collectionViewLayout:flowLy];
    
    
    self.mainCV.delegate = self;
    self.mainCV.dataSource = self;
    self.mainCV.pagingEnabled = YES;
    // 边界反弹效果关,第一页和最后一页不能滑
    self.mainCV.bounces = NO;
    self.mainCV.contentOffset = CGPointMake(0, 0);
    self.mainCV.showsHorizontalScrollIndicator = NO;
    self.mainCV.showsVerticalScrollIndicator = NO;
    [self.mainCV registerClass:[LJMUserCollectionViewCell class] forCellWithReuseIdentifier:@"user"];
    [self.mainCV registerClass:[LJMRecommendCollectionViewCell class] forCellWithReuseIdentifier:@"recommend"];
    [self.mainCV registerClass:[LJMDiscoverCollectionViewCell class] forCellWithReuseIdentifier:@"discover"];
    [self.view addSubview:self.mainCV];
    [_mainCV release];
}

#pragma collection的协议方法
#pragma 跟(小白条)的随动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.mainCV) {
        CGFloat n = scrollView.contentOffset.x / self.view.frame.size.width;
        self.headImageV.center = CGPointMake(self.userBut.center.x + n * (self.userBut.frame.size.width), self.userBut.frame.size.height + self.userBut.frame.origin.y - 1.5);
    }
}

#pragma 减速结束后的方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.mainCV) {
        NSInteger n = scrollView.contentOffset.x / self.view.frame.size.width;
        if (0 == n) {
            self.userBut.selected = YES;
            self.recommendBut.selected = NO;
            self.discoverBut.selected = NO;
        } else if (1 == n) {
            self.userBut.selected = NO;
            self.recommendBut.selected = YES;
            self.discoverBut.selected = NO;
        
        } else {
            self.userBut.selected = NO;
            self.recommendBut.selected = NO;
            self.discoverBut.selected = YES;

        }
    }
}

#pragma 数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

#pragma cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
        if (0 == indexPath.row) {
            self.userCVC = [collectionView dequeueReusableCellWithReuseIdentifier:@"user" forIndexPath:indexPath];
            
            [self.userCVC sendsBlock:^{
                
                NSLog(@"更换壁纸");
                self.wallpaperVC = [[SYP_WallpaperViewController alloc] init];
                [self.wallpaperVC sendImageBlock:^(UIImage *image) {
                   
                    self.userCVC.headerImageV.image = image;
                }];
                self.wallpaperVC.imageV.image = self.userCVC.headerImageV.image;
                [self.navigationController pushViewController:self.wallpaperVC animated:YES];
                
            }];
            
            return self.userCVC;
        } else if (1 == indexPath.row) {
        
#pragma 推荐界面cell
            self.recommendCVC = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommend" forIndexPath:indexPath];
            self.recommendCVC.delegate = self;
            self.recommendCVC.dataArr = self.suggestDataArr;
            return self.recommendCVC;
        
        } else {

            self.discoverCVC = [collectionView dequeueReusableCellWithReuseIdentifier:@"discover" forIndexPath:indexPath];
            if (0 == self.discoverCVC.discoverArr.count) {
                self.discoverCVC.discoverArr = [NSMutableArray arrayWithArray:self.discoverDataArr];
            }
            self.discoverCVC.delegate = self;
            return self.discoverCVC;
            
        }


}
#pragma 添加头视图上的三个button
- (void)addHeadBut
{
    self.userBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.navigationController.navigationBar addSubview:self.userBut];
    [self.userBut addTarget:self action:@selector(headButtonAction:) forControlEvents:UIControlEventTouchUpInside];
   
        self.userBut.selected = YES;
    self.userBut.backgroundColor = [UIColor clearColor];
    [self.userBut setTitle:@"我的" forState:UIControlStateNormal];
    self.userBut.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.userBut setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.userBut setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    
    self.userBut.frame = CGRectMake(LEFTBARBUTTONWIDTH, self.leftBarButton.frame.origin.y, (self.view.frame.size.width - LEFTBARBUTTONWIDTH - LEFTBARBUTTONWIDTH) / 3, LEFTBARBUTTONHEIGHT);
    
    self.recommendBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.navigationController.navigationBar addSubview:self.recommendBut];
    self.recommendBut.backgroundColor = [UIColor clearColor];
    [self.recommendBut setTitle:@"推荐" forState:UIControlStateNormal];
    self.recommendBut.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.recommendBut setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.recommendBut addTarget:self action:@selector(headButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    [self.recommendBut setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    
    self.recommendBut.frame = CGRectMake(self.userBut.frame.origin.x + self.userBut.frame.size.width, self.userBut.frame.origin.y, self.userBut.frame.size.width, self.userBut.frame.size.height);
    
    self.discoverBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.navigationController.navigationBar addSubview:self.discoverBut];
    self.discoverBut.backgroundColor = [UIColor clearColor];
    [self.discoverBut setTitle:@"发现" forState:UIControlStateNormal];
    self.discoverBut.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.discoverBut setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.discoverBut setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.discoverBut addTarget:self action:@selector(headButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.discoverBut.frame = CGRectMake(self.recommendBut.frame.origin.x + self.recommendBut.frame.size.width, self.recommendBut.frame.origin.y, self.recommendBut.frame.size.width, self.recommendBut.frame.size.height);
    
    
}
#pragma headBut的动作
- (void)headButtonAction:(UIButton *)sender
{
    if (sender == self.userBut) {
        self.userBut.selected = YES;
        self.recommendBut.selected = NO;
        self.discoverBut.selected = NO;
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
        [self.mainCV scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        
    }
    if (sender == self.recommendBut) {
        self.userBut.selected = NO;
        self.recommendBut.selected = YES;
        self.discoverBut.selected = NO;
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
        [self.mainCV scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    }
    if (sender == self.discoverBut) {
        self.userBut.selected = NO;
        self.recommendBut.selected = NO;
        self.discoverBut.selected = YES;
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:2 inSection:0];
        [self.mainCV scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    }

}
#pragma 添加navigationBar
- (void)addNavigationBar
{
    //设置成不透明
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:69 / 255.0 green:175 / 255.0 blue:248 / 255.0 alpha:1.0];
    //添加左侧的按钮
    [self addLeftBarView];
    //添加右侧的按钮
    [self addRightBarView];
}
#pragma 添加右侧搜索按钮在Navigation
- (void)addRightBarView
{
    self.rightBarView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - LEFTBARBUTTONWIDTH, 0, LEFTBARBUTTONWIDTH, LEFTBARBUTTONHEIGHT)];
    self.rightBarView.backgroundColor = [UIColor clearColor];
    self.rightBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rightBut.frame = self.rightBarView.bounds;
    [self.view addSubview:self.rightBarView];
    
    [self.rightBut setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
    self.rightBut.adjustsImageWhenHighlighted = NO;
    [self.rightBut addTarget:self action:@selector(barAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.rightBarView addSubview:self.rightBut];
    [self.navigationController.navigationBar addSubview:self.rightBarView];
    [_rightBarView release];
}
#pragma 添加左侧的按钮在Navigation
- (void)addLeftBarView
{
    self.leftBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LEFTBARBUTTONWIDTH, LEFTBARBUTTONHEIGHT)];
    self.leftBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBarButton.frame = self.leftBarView.frame;
    [self.view addSubview:self.leftBarView];
    
    [self.leftBarButton setImage:[UIImage imageNamed:@"leftbarbutton"] forState:UIControlStateNormal];
    self.leftBarButton.adjustsImageWhenHighlighted = NO;
    [self.leftBarButton addTarget:self action:@selector(barAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.leftBarView addSubview:self.leftBarButton];
    [self.navigationController.navigationBar addSubview:self.leftBarView];
    [_leftBarView release];
    

}

#pragma 点击拉抽屉_SYP
- (void)barAction:(UIButton *)sender
{
    if (sender == self.leftBarButton) {
        sender.selected = !sender.selected;
        
        if (sender.selected) {
            myBlock(1);
        } else {
            myBlock(0);
        }
 
    } else {
        
        LJM_SouSuo_ViewController *sousuoVC = [[LJM_SouSuo_ViewController alloc] init];
        sousuoVC.backDelegate = self;

        [self.navigationController pushViewController:sousuoVC animated:YES];
        [sousuoVC release];
        sousuoVC.navigationItem.hidesBackButton = YES;
        //移除navigationBar上的视图
        [self removeNavigationView];
        
    }
    
}

#pragma 拉抽屉的Block_SYP
- (void)sendBlock:(blockType)block
{
    myBlock = Block_copy(block);
}

#pragma DiscoverVC的协议方法进行页面跳转
- (void)changeVCUrl:(NSString *)str type:(NSString *)type
{
    //如果是点击DiscoverVC中的歌手按钮
    if ([type isEqualToString:@"Rank_soner"]) {
         LJMRank_sonerViewController *rank_sonerVC = [[LJMRank_sonerViewController alloc] init];
        [LJMNetworkTool getNetWithURL:str body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {
            if (nil != responseObject) {
               NSArray *arr = [responseObject objectForKey:@"data"];
                NSMutableArray *rankArr = [NSMutableArray array];
                for (NSMutableDictionary *tempDic in arr) {
                LJMRank_sonerModel *model = [[LJMRank_sonerModel alloc] init];
                    [model initWithDic:tempDic];
                    [rankArr addObject:model];
                    [model release];
                }
                rank_sonerVC.dataArr = [NSMutableArray arrayWithArray:rankArr];
                
            }
#pragma 缓存数据到本地
            NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
            // 存储的沙盒路径
            NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            // 归档
            [NSKeyedArchiver archiveRootObject:responseObject toFile:[path_doc stringByAppendingPathComponent:path]];
            
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            // 缓存的文件夹
            NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
            NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            // 反归档
            id result = [NSKeyedUnarchiver unarchiveObjectWithFile:[path_doc stringByAppendingPathComponent:path]];
            
            if (result) {
                NSArray *arr = [result objectForKey:@"data"];
                NSMutableArray *rankArr = [NSMutableArray array];
                for (NSMutableDictionary *tempDic in arr) {
                    LJMRank_sonerModel *model = [[LJMRank_sonerModel alloc] init];
                    [model initWithDic:tempDic];
                    [rankArr addObject:model];
                    [model release];
                }
                rank_sonerVC.dataArr = [NSMutableArray arrayWithArray:rankArr];

                
            } else {
                NSLog(@"error = %@", error);
            }

        }];
        
       
        rank_sonerVC.backDelegate = self;
        [self.navigationController pushViewController:rank_sonerVC animated:YES];
        rank_sonerVC.navigationItem.hidesBackButton = YES;
        [rank_sonerVC release];

    
    }
    if ([type isEqualToString:@"FM"]) {
        LJM_FM_ViewController *fmVC = [[LJM_FM_ViewController alloc] init];
        fmVC.backDelegate = self;

        [self.navigationController pushViewController:fmVC animated:YES];
        
        fmVC.navigationItem.hidesBackButton = YES;
        [fmVC release];
            NSMutableArray *dataArr = [NSMutableArray array];
        [LJMNetworkTool getNetWithURL:str body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {
            if (responseObject) {
                
         
            for (NSMutableDictionary *tempOneDic in [responseObject objectForKey:@"data"]) {
                LJMBase_FM_ONEModel *oneModel = [[LJMBase_FM_ONEModel alloc] init];
                [oneModel initWithDic:tempOneDic];
                oneModel.dataArr = [NSMutableArray array];
                for (NSMutableDictionary *tempDic in [tempOneDic objectForKey:@"data"]) {
                    LJMBase_FM_Model *model = [[LJMBase_FM_Model alloc] init];
                    
                    [model initWithDic:tempDic];
                    [oneModel.dataArr addObject:model];
                    [model release];
                }
                
                [dataArr addObject:oneModel];
                [oneModel release];
            }
            fmVC.dataArr = dataArr;
#pragma 缓存数据到本地
            NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
            // 存储的沙盒路径
            NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            // 归档
            [NSKeyedArchiver archiveRootObject:responseObject toFile:[path_doc stringByAppendingPathComponent:path]];
            
               }
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            // 缓存的文件夹
            NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
            NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            // 反归档
            id result = [NSKeyedUnarchiver unarchiveObjectWithFile:[path_doc stringByAppendingPathComponent:path]];
            
            if (result) {
                for (NSMutableDictionary *tempOneDic in [result objectForKey:@"data"]) {
                    LJMBase_FM_ONEModel *oneModel = [[LJMBase_FM_ONEModel alloc] init];
                    [oneModel initWithDic:tempOneDic];
                    oneModel.dataArr = [NSMutableArray array];
                    for (NSMutableDictionary *tempDic in [tempOneDic objectForKey:@"data"]) {
                        LJMBase_FM_Model *model = [[LJMBase_FM_Model alloc] init];
                        [model initWithDic:tempDic];
                        [oneModel.dataArr addObject:model];
                        [model release];
                        
                    }
                    
                    [dataArr addObject:oneModel];
                    [oneModel release];
                    
                }
                        fmVC.dataArr = dataArr;
  
            }
            
        }];
        
        
        
        
        
    }
        if ([type isEqualToString:@"SONG"]) {
            
            LJM_SONG_ViewController *songVC = [[LJM_SONG_ViewController alloc] init];
            songVC.navigationItem.hidesBackButton = YES;
            songVC.backDelegate = self;
            [self.navigationController pushViewController:songVC animated:YES];
            [songVC release];


            [LJMNetworkTool getNetWithURL:str body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {

                if (responseObject) {
                    NSMutableArray *arr = [NSMutableArray array];
                    for (NSMutableDictionary *tempDic in [responseObject objectForKey:@"data"]) {
                        LJM_SONG_Main_Model *model = [[LJM_SONG_Main_Model alloc] init];
                        [model initWithDic:tempDic];
                        [arr addObject:model];

                        [model release];
                        
                    }
                    songVC.dataArr = arr;

                    
#pragma 缓存数据到本地
                    NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
                    // 存储的沙盒路径
                    NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
                    // 归档
                    [NSKeyedArchiver archiveRootObject:responseObject toFile:[path_doc stringByAppendingPathComponent:path]];
                    
                }
                
                
                
            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                // 缓存的文件夹
                NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
                NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
                // 反归档
                id result = [NSKeyedUnarchiver unarchiveObjectWithFile:[path_doc stringByAppendingPathComponent:path]];
                
                if (result) {
                    NSMutableArray *arr = [NSMutableArray array];
                    for (NSMutableDictionary *tempDic in [result objectForKey:@"data"]) {
                        LJM_SONG_Main_Model *model = [[LJM_SONG_Main_Model alloc] init];
                        [model initWithDic:tempDic];
                        [arr addObject:model];
                        [model release];
                    }
                    songVC.dataArr = arr;
                    
                }
            }];
            
            
        }
    
            if ([type isEqualToString:@"RANK"]) {
                LJM_RANK_ViewController *rankVC = [[LJM_RANK_ViewController alloc] init];
                rankVC.backDelegate = self;
                rankVC.URLSTR = str;
                rankVC.navigationItem.hidesBackButton = YES;
                [self.navigationController pushViewController:rankVC animated:YES];
                [rankVC release];
                
            }
    
    
    //移除navigationBar上的视图
    [self removeNavigationView];
    
    
    
}
#pragma DiscoverVC的协议方法 - ListentableViewCell的协议方法 MOVE
- (void)changeMoveVCUrl:(NSString *)str
{
    LJM_ListenMove_ViewController *listenMoveVC = [[LJM_ListenMove_ViewController alloc] init];
    listenMoveVC.backDelegate = self;
    listenMoveVC._id = @"0";
    [self.navigationController pushViewController:listenMoveVC animated:YES];
    [listenMoveVC release];
    listenMoveVC.navigationItem.hidesBackButton = YES;
    //移除navigationBar上的视图
    [self removeNavigationView];
}

#pragma RANK中返回的动作
- (void)backRANKAction
{
        [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}

#pragma rank中的返回动作
- (void)backRankAction
{
        [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}
#pragma FM中返回的动作
- (void)backFMAction
{
        [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}
#pragma 搜索的返回动作
- (void)backSousuoVCAction
{
        [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}
#pragma SONG中的返回动作
- (void)backSONGAction
{
        [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}

#pragma ListenMove中的返回动作
- (void)ListenMOVEBackNavigationDelegate
{
    [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}

#pragma hotSong进入song_root_sub界面
- (void)changeHotSongToSong_Root_sub:(LJM_HotSong_Model *)model;
{
    LJM_SONG_Root_Sub_ViewController *subVC = [[LJM_SONG_Root_Sub_ViewController alloc] init];
    subVC.backDelegate = self;
    subVC.type = @"SONG";
    subVC.imageUrl = model.picUrl;
    subVC._id = model.value;
    [self.navigationController pushViewController:subVC animated:YES];
    [subVC release];
    subVC.navigationItem.hidesBackButton = YES;
    //移除navigationBar上的视图
    [self removeNavigationView];
}
#pragma song_root_subVC的协议方法
- (void)SubBackNavigationDelegate
{
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];

}


#pragma ListentableViewCell的协议方法 cell点击(大家在听的播放实现)_SYP
- (void)changeCellVCUrl:(NSInteger)n
{
    // 获取"大家在听"的数据
    [self getDataWith:n];

}

#pragma 解析大家在听的数据_SYP
- (void)getDataWith:(NSInteger)n
{
    [LJMNetworkTool getNetWithURL:LISTENMOVEURL body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableDictionary *dictionary = responseObject;
        NSMutableDictionary *dic = dictionary[@"data"];
        NSMutableArray *array = dic[@"songs"];
        self.playerMusicArr = [LJMListen_Model baseModelWithArr:array];
        
        // 开始播放
        [self playMusicWithArr:self.playerMusicArr index:n];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
    }];
}
#pragma activity更多切换到VC中 更多
- (void)changeActivityMoveToVC:(NSString *)str
{
    LJM_ActivityMoreVC_ViewController *activityMVC = [[LJM_ActivityMoreVC_ViewController alloc] init];
    activityMVC.backDelegate = self;
    activityMVC.navigationItem.hidesBackButton = YES;
    [self removeNavigationView];
    [self.navigationController pushViewController:activityMVC animated:YES];
    [activityMVC release];
    NSMutableArray *activityArr = [NSMutableArray array];
    [LJMNetworkTool getNetWithURL:str body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        if (responseObject) {
     
        for (NSMutableDictionary *tempDic in [responseObject objectForKey:@"data"]) {
            LJM_ActivityMoreVC_Model *model = [[LJM_ActivityMoreVC_Model alloc] init];
            [model initWithDic:tempDic];
            [activityArr addObject:model];
            [model release];
        }
                    activityMVC.dataArr = activityArr;
        }

#pragma 缓存数据到本地
        NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
        // 存储的沙盒路径
        NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        // 归档
        [NSKeyedArchiver archiveRootObject:responseObject toFile:[path_doc stringByAppendingPathComponent:path]];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        // 缓存的文件夹
        NSString *path = [NSString stringWithFormat:@"%ld.plist", (long)[str hash]];
        NSString *path_doc = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        // 反归档
        id result = [NSKeyedUnarchiver unarchiveObjectWithFile:[path_doc stringByAppendingPathComponent:path]];
        
        if (result) {
            
            for (NSMutableDictionary *tempDic in [result objectForKey:@"data"]) {
                LJM_ActivityMoreVC_Model *model = [[LJM_ActivityMoreVC_Model alloc] init];
                [model initWithDic:tempDic];
                [activityArr addObject:model];
                [model release];
            }
            activityMVC.dataArr = activityArr;
        }
        
    }];
    
    
}
#pragma activity到webView的方法
- (void)changeActivityToWebView:(NSString *)str
{
    LJM_RANK_WebView_ViewController *webView = [[LJM_RANK_WebView_ViewController alloc] init];
    webView.backDelegate = self;
    webView.navigationItem.hidesBackButton = YES;
    webView.url = str;
    [self removeNavigationView];
    [self.navigationController pushViewController:webView animated:YES];
    [webView release];
}
#pragma webView返回协议动作的方法
- (void)backRANK_WebView_Delegate
{
    [self addRightBarView];
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}
#pragma actionMore的返回动作
- (void)backActionMoreVCAction
{
    [self addHeadBut];
    [self creatHeatView];
    [self addLeftBarView];
    [self decideCollectionCell];
}
#pragma 点击电台的播放方法
- (void)jumpPageWithArr:(NSMutableArray *)arr indexRow:(NSInteger)musicListIndexRow indexSection:(NSInteger)indexSection
{
    NSInteger index = indexSection * 100 + musicListIndexRow;
    [self playMusicWithArr:arr musicListIndex:index];
    
}



#pragma 判断现在到底谁是主界面
- (void)decideCollectionCell
{
    NSInteger n = self.mainCV.contentOffset.x / self.view.frame.size.width;
    if (0 == n) {
        self.userBut.selected = YES;
        self.recommendBut.selected = NO;
        self.discoverBut.selected = NO;
    } else if (1 == n) {
        self.userBut.selected = NO;
        self.recommendBut.selected = YES;
        self.discoverBut.selected = NO;
        
    } else {
        self.userBut.selected = NO;
        self.recommendBut.selected = NO;
        self.discoverBut.selected = YES;
        
    }

}

#pragma 移除navigationBar上的视图
- (void)removeNavigationView
{
    [self.rightBarView removeFromSuperview];
    [self.leftBarView removeFromSuperview];
    [self.headImageV removeFromSuperview];
    [self.userBut removeFromSuperview];
    [self.recommendBut removeFromSuperview];
    [self.discoverBut removeFromSuperview];
}

// 传到音乐播放界面播放
#pragma 推荐界面点击播放音乐
- (void)playWithAuditionListArr:(NSMutableArray *)musicListArr index:(NSInteger)index
{
    [self playMusicWithArr:musicListArr index:index];
}


#pragma 点击跳转的大方法_SYP

// 第一种: 点击单个歌曲类型的大方法
- (void)playMusicWithArr:(NSMutableArray *)musicListArr index:(NSInteger)index
{
    self.musicVC = [SYPMusicPlay_ViewController shareMusicPlayVC];
    self.musicVC.MusicsArr = musicListArr;
    self.playerMusicArr = musicListArr;
    self.mainIndex = index;
    self.musicVC.index = index;
    [self.musicListTableView reloadData];
    
    LJMListen_Model *mod = nil;
    NSLog(@"数组个数:%ld", musicListArr.count);
    if (0 != musicListArr.count) {
        mod = musicListArr[index];
    }
    self.musicName.text = mod.name;
    self.singerName.text = mod.singerName;
    [self.singerImageV sd_setImageWithURL:[NSURL URLWithString:mod.picUrl] placeholderImage:[UIImage imageNamed:@"CD"]];
    NSMutableDictionary *dic = mod.auditionListArr[1];
    self.musicVC.musicURL = dic[@"url"];

    if (self.musicVC.player) {
        NSLog(@"已经存在播放器");
        
        if (self.musicVC.musicURL == self.playerMusicUrl) {
            NSLog(@"点击的同一首歌");
            switch (self.musicVC.player.state) {
                    
                case STKAudioPlayerStatePlaying:
                    NSLog(@"播放状态, 暂停");
                    [self.musicVC.player pause];
                    self.playButton.selected = NO;
                    self.musicVC.states = 0;
                    break;
                    
                case STKAudioPlayerStatePaused:
                    NSLog(@"暂停状态, 播放");
                    [self.musicVC.player resume];
                    self.playButton.selected = YES;
                    self.musicVC.states = 1;
                    break;
                    
                case STKAudioPlayerStateBuffering:
                    NSLog(@"缓存状态");
                    break;
                    
                default:
                    break;
            }
            
        } else {
            
            NSLog(@"点击的不是同一首歌");
            [self.musicVC.player stop];
            [self.musicVC.player release];
            [self.musicVC creatPlayerWithMusicName:self.musicVC.musicURL];
            self.playerMusicUrl = self.musicVC.musicURL;
            self.musicVC.index = index;
            self.playButton.selected = YES;
            self.musicVC.states = 1;
        }
        
    } else {
        NSLog(@"还没有播放器, 创建播发器");
        [self.musicVC creatPlayerWithMusicName:self.musicVC.musicURL];
        self.playerMusicUrl = self.musicVC.musicURL;
        self.playButton.selected = YES;
        self.musicVC.index = index;
        self.musicVC.states = 1;
        NSLog(@"已经创建播放器");
    }
    
}

// 第二种: 点击单个歌曲分组的大方法
- (void)playMusicWithArr:(NSMutableArray *)musicListArr musicListIndex:(NSInteger)musicListIndex
{
    // 创建播放对象
    self.musicVC = [SYPMusicPlay_ViewController shareMusicPlayVC];

    // 播放状态
    if (1 == self.musicVC.states) {
        
        // 点击的是同一个分组(暂停歌曲播放)
        if (musicListIndex == self.tempIndex) {
            
            NSLog(@"点击的是同一个分组(已经暂停歌曲播放)");
            
            [self.musicVC.player pause];  // 暂停
            self.musicVC.states = 0;  // 改为暂停状态
            self.playButton.selected = NO;  //按钮改为暂停状态
            
            // 点击的不是同一首歌(开始播放新的音乐列表)
        } else {
            
            NSLog(@"点击的不是同一个音乐分组(开始播放新的音乐列表)");
            
            // 传值给播放器
            self.musicVC.MusicsArr = musicListArr;
            self.musicVC.index = 0;
            
            self.playerMusicArr = musicListArr;
            self.mainIndex = 0;
            
            [self.musicListTableView reloadData];
            
            // 清除旧的的播放器
            [self.musicVC.player stop];
            [self.musicVC.player release];
            
            // 创建新的播放器
            if (0 != musicListArr.count) {
                
                NSLog(@"开始播放新的音乐数组");
                LJMListen_Model *mod = musicListArr[self.musicVC.index];
                NSMutableDictionary *dic = mod.auditionListArr[1];
                NSString *musicName = dic[@"url"];
                self.musicVC.musicURL = musicName;
                
                self.musicVC.musicName.text = mod.name;
                self.musicVC.singerName.text = mod.singerName;
                self.singerName.text = mod.singerName;
                self.musicName.text = mod.name;
                
                [self.musicVC creatPlayerWithMusicName:musicName];
                self.playButton.selected = 1;
            }

            
            
        }
        self.tempIndex = musicListIndex;
        
        // 未播放状态
    } else {
        
        // 暂停状态
        if (self.musicVC.player.state == STKAudioPlayerStatePaused) {
            NSLog(@"正是暂停状态, 开始继续播放");
            [self.musicVC.player resume];
            self.musicVC.states = 1;
            self.playButton.selected = YES;
            
            // 还没选歌,播放选中歌曲
        } else {
            NSLog(@"还没选歌,播放选中歌曲");
            
            // 传值给播放器
            self.musicVC.MusicsArr = musicListArr;
            self.musicVC.index = 0;
            
            
            self.playerMusicArr = musicListArr;
            self.mainIndex = 0;
            [self.musicListTableView reloadData];
            // 创建新的播放器
            if (0 != musicListArr.count) {
                
                NSLog(@"开始播放第一次选中的音乐数组");
                LJMListen_Model *mod = musicListArr[self.musicVC.index];
                NSMutableDictionary *dic = mod.auditionListArr[1];
                NSString *musicName = dic[@"url"];
                self.musicVC.musicURL = musicName;
                
                self.musicVC.musicName.text = mod.name;
                self.musicVC.singerName.text = mod.singerName;
                self.singerName.text = mod.name;
                self.musicName.text = mod.singerName;
                
                [self.musicVC creatPlayerWithMusicName:musicName];
                self.playButton.selected = 1;
            }
        }
        
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
